Libraries

The following libraries were used:

library(tidyverse)
library(here)
library(vegan)

Data wrangling and creating plots

Using nested for loops, R cycles through all six lakes and finds the three most abundant species per lake. It then creates boxplots of these three species and their matching lake.

load(file = here("data/data_tidy.RData")) # load object data_tidy

lakes <- unique(data_tidy$LakeName)

years <- unique(data_tidy$Year)

for (i in 1:length(lakes)){
  Ldata <- data_tidy %>% filter(LakeName == lakes[i]) 
  
  for (j in 1:length(years)){
    Ydata <- filter(Ldata, Year == years[j])
    
    if (nrow(Ydata) > 0) {

Mdata <- Ydata %>% group_by(Month, Species, LakeName) %>% summarize(Count = sum(Counts, na.rm = TRUE))

summary <- Mdata[c("Month", "Species", "Count")] %>% group_by(Month) %>% summarize(richness = specnumber(Count),
                                                                        shannon = diversity(Count, index = "shannon"),
                                                                        simpson = diversity(Count, index = "simpson"),
                                                                        invsimpson = 1/simpson,
                                                                        total = sum(Count),
                                                                        evenness = shannon/log(richness))

result <- summary %>% pivot_longer(cols = c(richness, shannon, simpson, invsimpson, evenness),
                         names_to = "metric",
                         values_to = "Count") %>%
  ggplot(aes(x = total, y = Count))+
  geom_point()+
  geom_smooth()+
  facet_wrap(~metric, nrow = 5, scales = "free_y")+
  labs(y = "Value",
       x = "Number of counts",
       title = paste0(lakes[i], " in ", years[j]))

print(result)
print(knitr::kable(summary, 
             format = "markdown",
             caption = paste0("Diversity indices of ", lakes[i], " in ", years[j]),
             label = "--------------------------------------------------"))

    } else {
      warning(paste0("No data for ", lakes[[i]], "in the year ", years[[j]]))
    }
  }
}

Diversity indices of Coneries Lake in 2005
Month richness shannon simpson invsimpson total evenness
Mar 6 1.0678320 0.5574223 1.793972 111 0.5959684
Apr 5 1.1500732 0.6714446 1.489326 275 0.7145807
May 4 0.7256543 0.4621378 2.163857 111 0.5234490
Jun 3 0.6500978 0.4317417 2.316200 158 0.5917445
Jul 4 0.6276730 0.3271948 3.056283 182 0.4527704
Aug 4 0.2777384 0.1284607 7.784480 526 0.2003459
Oct 3 0.7770180 0.5078135 1.969227 235 0.7072722
Nov 4 0.8199702 0.4405517 2.269881 257 0.5914835
Dec 4 1.0753237 0.6308284 1.585217 94 0.7756821

Diversity indices of Coneries Lake in 2006
Month richness shannon simpson invsimpson total evenness
Jan 3 1.0437249 0.6294643 1.588653 56 0.9500393
Feb 4 0.8452884 0.4422187 2.261325 109 0.6097467
Mar 4 1.2650218 0.6923783 1.444297 33 0.9125203
Apr 4 1.2324079 0.6814134 1.467538 118 0.8889944
May 3 0.6437436 0.3987783 2.507659 113 0.5859607
Jun 5 0.8575816 0.4695065 2.129896 146 0.5328454
Jul 3 0.6778898 0.4611687 2.168404 370 0.6170419
Aug 5 0.7548043 0.4553336 2.196192 278 0.4689863
Sep 3 0.3589365 0.1792595 5.578505 550 0.3267181
Oct 5 0.6424588 0.3010834 3.321339 252 0.3991821
Nov 6 1.0212590 0.5623358 1.778297 327 0.5699755
Dec 4 0.6531317 0.3898376 2.565171 98 0.4711349

Diversity indices of Coneries Lake in 2007
Month richness shannon simpson invsimpson total evenness
Jan 2 0.5359599 0.3512397 2.847059 22 0.7732267
Feb 3 1.0986123 0.6666667 1.500000 3 1.0000000
Mar 3 0.7259004 0.4089415 2.445338 39 0.6607431
Apr 5 1.0973801 0.5825987 1.716447 182 0.6818406
May 6 0.5567700 0.2425926 4.122137 180 0.3107393
Jun 5 0.8171707 0.5144063 1.943989 333 0.5077367
Jul 5 1.0102789 0.5587050 1.789853 126 0.6277216
Aug 4 0.4293327 0.1981576 5.046488 222 0.3096981
Sep 5 1.3487308 0.6990568 1.430499 257 0.8380136
Oct 4 0.5990987 0.3126990 3.197963 267 0.4321584
Nov 5 1.2805010 0.6893827 1.450573 135 0.7956200
Dec 4 1.0050746 0.5951557 1.680233 119 0.7250081

Diversity indices of Coneries Lake in 2008
Month richness shannon simpson invsimpson total evenness
Jan 3 1.076819 0.6528000 1.531863 25 0.9801626
Feb 3 0.719329 0.4362140 2.292453 27 0.6547615
Mar 8 1.048079 0.5122182 1.952293 203 0.5040196

Diversity indices of Tween Pond in 2005
Month richness shannon simpson invsimpson total evenness
Mar 5 1.2546696 0.6470000 1.545595 100 0.7795700
Apr 5 1.3947284 0.7386418 1.353836 219 0.8665935
May 4 0.7603040 0.5117770 1.953976 158 0.5484434
Jun 3 0.7185158 0.4912082 2.035796 119 0.6540213
Jul 4 0.1223975 0.0408602 24.473719 193 0.0882912
Aug 3 0.2576588 0.1118151 8.943335 375 0.2345312
Oct 3 0.7103404 0.4293802 2.328939 166 0.6465797
Nov 5 0.8639936 0.4338019 2.305200 109 0.5368294
Dec 5 1.1454479 0.5900731 1.694705 63 0.7117068

Diversity indices of Tween Pond in 2006
Month richness shannon simpson invsimpson total evenness
Jan 2 0.4505612 0.2777778 3.600000 6 0.6500224
Feb 4 0.6495700 0.3308642 3.022388 135 0.4685657
Mar 3 0.9922820 0.6020408 1.661017 14 0.9032140
Apr 6 1.5036560 0.7554816 1.323659 145 0.8392064
May 4 0.9670561 0.5532893 1.807373 118 0.6975835
Jun 4 0.9338145 0.5315762 1.881198 174 0.6736048
Jul 4 0.2642994 0.1124132 8.895753 288 0.1906517
Aug 4 0.4537789 0.2429174 4.116625 309 0.3273323
Oct 5 0.9651100 0.4992696 2.002926 283 0.5996566
Nov 5 1.0883452 0.5929167 1.686578 120 0.6762269
Dec 3 1.0789922 0.6530612 1.531250 7 0.9821410

Diversity indices of Tween Pond in 2007
Month richness shannon simpson invsimpson total evenness
Jan 1 0.0000000 0.0000000 Inf 7 NaN
Feb 2 0.6730117 0.4800000 2.083333 5 0.9709506
Mar 3 0.8237197 0.5150000 1.941748 20 0.7497820
Apr 5 1.2139361 0.6700661 1.492390 118 0.7542609
May 5 1.2235244 0.6169100 1.620982 129 0.7602184
Jun 4 0.7924457 0.4403841 2.270745 270 0.5716287
Jul 5 1.2907814 0.6632653 1.507692 28 0.8020076
Aug 4 1.0031587 0.5430624 1.841409 115 0.7236260
Sep 5 0.9694634 0.5541790 1.804471 104 0.6023615
Oct 6 1.1967677 0.6623309 1.509819 124 0.6679288
Nov 4 0.8208898 0.4706515 2.124714 167 0.5921468
Dec 2 0.6931472 0.5000000 2.000000 4 1.0000000

Diversity indices of Tween Pond in 2008
Month richness shannon simpson invsimpson total evenness
Jan 2 0.6829081 0.4897959 2.041667 7 0.9852281
Feb 2 0.6730117 0.4800000 2.083333 5 0.9709506
Mar 3 0.8675632 0.5000000 2.000000 12 0.7896901

Diversity indices of Tween Pond in 2010
Month richness shannon simpson invsimpson total evenness
Jan 4 1.3862944 0.7500000 1.333333 4 1.0000000
Feb 2 0.6931472 0.5000000 2.000000 2 1.0000000
Mar 3 0.7963116 0.4489796 2.227273 7 0.7248341
Apr 3 0.6711538 0.3676269 2.720149 54 0.6109105
May 3 1.0661683 0.6456552 1.548814 401 0.9704682
Jun 2 0.3119624 0.1705190 5.864448 85 0.4500667
Jul 3 1.0906868 0.6614479 1.511835 118 0.9927859
Aug 3 0.7222124 0.4057727 2.464434 142 0.6573860
Sep 4 1.2379635 0.6807732 1.468918 213 0.8930019
Oct 4 0.7869196 0.4609911 2.169239 216 0.5676425
Nov 3 0.7924891 0.4917355 2.033613 22 0.7213547

Diversity indices of Tween Pond in 2011
Month richness shannon simpson invsimpson total evenness
Jan 3 0.8486856 0.4938272 2.025000 9 0.7725069
Feb 0 0.0000000 1.0000000 1.000000 0 0.0000000
Mar 4 0.9792377 0.5708885 1.751656 23 0.7063707
Apr 3 0.9198802 0.5540466 1.804902 256 0.8373110
May 3 0.7006403 0.4623458 2.162883 158 0.6377503
Jun 4 0.7141995 0.4377506 2.284406 298 0.5151860
Jul 3 0.1956700 0.0776000 12.886598 100 0.1781065
Aug 2 0.0228597 0.0068259 146.501718 292 0.0329796
Sep 3 0.9660921 0.5869326 1.703773 362 0.8793749
Oct 3 0.9928291 0.5993402 1.668501 229 0.9037119
Nov 2 0.2416289 0.1222814 8.177857 107 0.3485969
Dec 4 0.5503540 0.2716049 3.681818 117 0.3969965

Diversity indices of Tween Pond in 2012
Month richness shannon simpson invsimpson total evenness
Jan 2 0.2654460 0.1381154 7.240323 134 0.3829577
Feb 2 0.6305810 0.4387500 2.279202 40 0.9097361
Mar 2 0.1849074 0.0867769 11.523810 22 0.2667650

Diversity indices of Main Pond in 2005
Month richness shannon simpson invsimpson total evenness
Mar 4 0.6755411 0.3837779 2.605674 206 0.4872999
Apr 3 0.7999523 0.4606622 2.170788 106 0.7281479
May 4 0.6819218 0.4030073 2.481345 113 0.4919026
Jun 4 0.9518855 0.5309695 1.883347 95 0.6866402
Jul 2 0.3887026 0.2280052 4.385866 221 0.5607793
Aug 2 0.1598359 0.0721419 13.861572 507 0.2305945
Oct 3 0.5886965 0.3099218 3.226620 139 0.5358546
Nov 3 0.4722595 0.2476200 4.038446 199 0.4298691
Dec 5 0.7501744 0.3735198 2.677234 126 0.4661096

Diversity indices of Main Pond in 2006
Month richness shannon simpson invsimpson total evenness
Jan 3 0.6749754 0.3923611 2.548673 24 0.6143891
Feb 5 0.9830617 0.5194709 1.925036 116 0.6108106
Mar 3 1.0106064 0.6082206 1.644140 62 0.9198936
Apr 6 1.2651170 0.6374182 1.568829 164 0.7060752
May 5 1.2189788 0.6591490 1.517108 148 0.7573941
Jun 5 0.9796860 0.4959782 2.016218 236 0.6087131
Aug 3 0.3986352 0.2237466 4.469342 274 0.3628534
Sep 4 0.7149946 0.4097148 2.440722 318 0.5157596
Oct 5 0.9090150 0.5354246 1.867677 172 0.5648028
Nov 5 0.7696841 0.4111797 2.432027 108 0.4782316
Dec 1 0.0000000 0.0000000 Inf 60 NaN

Diversity indices of Main Pond in 2007
Month richness shannon simpson invsimpson total evenness
Jan 3 0.9743148 0.5937500 1.684211 8 0.8868595
Feb 2 0.6365142 0.4444444 2.250000 3 0.9182958
Mar 4 1.1537419 0.6122449 1.633333 7 0.8322489
Apr 5 0.8946474 0.4464758 2.239763 202 0.5558757
May 4 0.9152700 0.4934641 2.026490 102 0.6602278
Jun 3 0.6458246 0.4231104 2.363449 379 0.5878549
Jul 4 0.8337069 0.4218496 2.370513 43 0.6013924
Aug 6 1.0053318 0.5250726 1.904499 177 0.5610863
Sep 5 1.0469684 0.5881679 1.700195 225 0.6505180
Oct 3 0.3952459 0.2122506 4.711412 251 0.3597683
Nov 4 0.7755325 0.3951247 2.530847 193 0.5594284
Dec 3 0.5783253 0.3044983 3.284091 17 0.5264144

Diversity indices of Main Pond in 2008
Month richness shannon simpson invsimpson total evenness
Jan 2 0.5297062 0.3456790 2.892857 9 0.7642045
Feb 4 1.2770343 0.6938776 1.441177 7 0.9211855
Mar 4 0.9371559 0.4852071 2.060976 13 0.6760151

Diversity indices of Church Pond in 2005
Month richness shannon simpson invsimpson total evenness
Mar 3 0.5771536 0.3385034 2.954180 105 0.5253478
Apr 3 0.9893054 0.5893877 1.696676 129 0.9005046
May 3 0.4409809 0.2505207 3.991685 158 0.4013981
Jun 3 0.9771705 0.5892857 1.696970 56 0.8894589
Jul 2 0.6791933 0.4861111 2.057143 12 0.9798688
Aug 3 1.0027400 0.6020761 1.660920 17 0.9127332
Oct 4 0.8732006 0.5316213 1.881038 137 0.6298811
Nov 5 0.6812346 0.4122785 2.425545 378 0.4232749
Dec 3 0.6262751 0.3730159 2.680851 168 0.5700602

Diversity indices of Church Pond in 2006
Month richness shannon simpson invsimpson total evenness
Jan 3 0.8175442 0.5320310 1.879590 59 0.7441608
Feb 2 0.4002239 0.2370491 4.218535 131 0.5774011
Mar 3 1.0013211 0.6048038 1.653429 145 0.9114417
Apr 0 0.0000000 1.0000000 1.000000 0 0.0000000
May 4 0.9296842 0.5217280 1.916708 125 0.6706254
Jul 5 1.3350466 0.6944444 1.440000 24 0.8295111
Aug 3 0.5181862 0.2650000 3.773585 20 0.4716734
Sep 3 0.1328197 0.0490278 20.396601 120 0.1208977
Oct 4 0.9761841 0.5545936 1.803122 230 0.7041680
Nov 4 1.3258597 0.7219505 1.385136 231 0.9564056
Dec 4 0.8266293 0.4518959 2.212899 129 0.5962870

Diversity indices of Church Pond in 2007
Month richness shannon simpson invsimpson total evenness
Jan 5 1.3547657 0.7145377 1.399506 63 0.8417632
Feb 4 0.8887559 0.5448560 1.835347 135 0.6411019
Mar 3 1.0599942 0.6428434 1.555589 144 0.9648483
Apr 6 1.0929324 0.5968133 1.675566 145 0.6099772
May 3 0.9757119 0.5790935 1.726837 176 0.8881313
Jun 4 0.6534463 0.3150000 3.174603 100 0.4713618
Jul 3 0.5654190 0.3272000 3.056235 100 0.5146666
Aug 4 1.1540628 0.6745800 1.482404 74 0.8324803
Sep 7 1.4478206 0.6772644 1.476528 107 0.7440326
Oct 4 0.7383424 0.4496107 2.224146 136 0.5326015
Nov 7 1.3182471 0.5958505 1.678273 108 0.6774450
Dec 6 0.5315330 0.2261850 4.421159 162 0.2966542

Diversity indices of Church Pond in 2008
Month richness shannon simpson invsimpson total evenness
Jan 6 1.373957 0.6880278 1.453430 146 0.7668197
Feb 6 1.126446 0.5972222 1.674419 132 0.6286814
Mar 5 1.030365 0.5612601 1.781705 391 0.6402018

Diversity indices of Clifton Pond in 2005
Month richness shannon simpson invsimpson total evenness
Apr 4 1.1915843 0.6787119 1.473379 97 0.8595464
May 4 1.1638764 0.6762425 1.478760 118 0.8395593
Jun 2 0.6682485 0.4753086 2.103896 18 0.9640788
Jul 2 0.5468520 0.3609917 2.770147 55 0.7889407
Aug 4 1.2876230 0.7029508 1.422575 204 0.9288237
Oct 6 1.2508617 0.6885494 1.452329 257 0.6981192
Nov 4 0.5929874 0.2789554 3.584803 275 0.4277500
Dec 3 0.7153379 0.4062564 2.461500 121 0.6511286

Diversity indices of Clifton Pond in 2006
Month richness shannon simpson invsimpson total evenness
Jan 3 0.8968346 0.5305362 1.884885 101 0.8163340
Feb 4 1.1947841 0.6607095 1.513524 122 0.8618545
Mar 4 1.1375794 0.6171881 1.620252 119 0.8205901
Apr 5 1.1814207 0.6685653 1.495740 159 0.7340580
May 4 1.1999621 0.6588921 1.517699 98 0.8655897
Jun 3 1.0397208 0.6250000 1.600000 8 0.9463946
Jul 3 0.3023050 0.1445942 6.915906 103 0.2751698
Aug 7 1.3192952 0.6145515 1.627203 107 0.6779836
Sep 5 0.9226983 0.4899688 2.040946 310 0.5733047
Oct 6 1.5024044 0.7160133 1.396622 111 0.8385079
Nov 6 0.5816301 0.2436523 4.104209 323 0.3246139
Dec 2 0.6024403 0.4120708 2.426768 155 0.8691376

Diversity indices of Clifton Pond in 2007
Month richness shannon simpson invsimpson total evenness
Jan 2 0.2426089 0.1229224 8.135211 76 0.3500106
Feb 5 1.0852519 0.5682275 1.759858 59 0.6743049
Mar 7 0.8950131 0.3847238 2.599267 153 0.4599457
Apr 8 1.0792169 0.5077810 1.969353 127 0.5189936
May 6 1.4465768 0.7210219 1.386920 108 0.8073499
Jun 6 1.1257337 0.5606020 1.783797 61 0.6282840
Jul 7 0.8424064 0.4161353 2.403064 494 0.4329112
Aug 5 0.6458239 0.3135448 3.189336 139 0.4012730
Sep 5 0.7646237 0.3752790 2.664684 194 0.4750874
Oct 4 1.0057145 0.5858726 1.706856 114 0.7254697
Nov 2 0.5623351 0.3750000 2.666667 8 0.8112781
Dec 2 0.2048671 0.0989036 10.110856 115 0.2955608

Diversity indices of Clifton Pond in 2008
Month richness shannon simpson invsimpson total evenness
Jan 3 0.8167753 0.5303210 1.885650 29 0.7434609
Feb 1 0.0000000 0.0000000 Inf 2 NaN
Mar 3 0.6758292 0.3649587 2.740036 55 0.6151663

Diversity indices of Clifton Pond in 2010
Month richness shannon simpson invsimpson total evenness
Jan 2 0.6365142 0.4444444 2.250000 3 0.9182958
Feb 1 0.0000000 0.0000000 Inf 2 NaN
Apr 1 0.0000000 0.0000000 Inf 76 NaN
May 3 0.1514124 0.0574779 17.397993 102 0.1378215
Jun 3 1.0986123 0.6666667 1.500000 3 1.0000000
Jul 3 0.8018186 0.4600000 2.173913 10 0.7298467
Aug 4 0.9169469 0.4861224 2.057095 140 0.6614374
Sep 7 1.4280940 0.6851457 1.459544 274 0.7338951
Oct 6 1.6287853 0.7777778 1.285714 36 0.9090424
Nov 3 1.0411315 0.6301775 1.586855 26 0.9476787

Diversity indices of Clifton Pond in 2011
Month richness shannon simpson invsimpson total evenness
Jan 4 0.8724528 0.5075614 1.970205 46 0.6293417
Feb 3 0.8139712 0.5285837 1.891848 59 0.7409085
Mar 3 0.7579333 0.5073255 1.971121 118 0.6899006
Apr 2 0.1029667 0.0416478 24.010870 47 0.1485495
May 4 1.2157231 0.6692708 1.494163 48 0.8769589
Jun 2 0.5541932 0.3676124 2.720256 103 0.7995318
Jul 5 1.1219843 0.5745391 1.740525 83 0.6971280
Aug 2 0.3488321 0.1975309 5.062500 9 0.5032583
Sep 5 1.3664956 0.7087291 1.410976 262 0.8490515
Oct 5 0.9987785 0.5156250 1.939394 32 0.6205760
Nov 5 1.2284141 0.6087990 1.642578 29 0.7632566
Dec 4 1.1355507 0.6260388 1.597345 19 0.8191267

Diversity indices of Clifton Pond in 2012
Month richness shannon simpson invsimpson total evenness
Jan 4 1.265413 0.7022222 1.424051 15 0.9128026
Feb 1 0.000000 0.0000000 Inf 13 NaN
Mar 6 1.047629 0.5455086 1.833152 82 0.5846928

Diversity indices of Beeston Pond in 2005
Month richness shannon simpson invsimpson total evenness
Apr 4 0.5268265 0.3051092 3.277515 276 0.3800250
May 5 0.7564715 0.4119569 2.427438 102 0.4700222
Jun 8 1.5456471 0.7500672 1.333214 122 0.7432991
Jul 3 0.1314906 0.0484344 20.646504 243 0.1196879
Aug 6 1.3309380 0.7043445 1.419760 102 0.7428106
Oct 5 0.4004220 0.1617687 6.181665 210 0.2487962
Nov 5 0.8257721 0.5242920 1.907334 307 0.5130810
Dec 5 0.9260287 0.5463842 1.830214 185 0.5753740

Diversity indices of Beeston Pond in 2006
Month richness shannon simpson invsimpson total evenness
Jan 5 1.0621756 0.5586976 1.789877 161 0.6599668
Feb 5 0.8321394 0.4323840 2.312759 125 0.5170373
Mar 6 1.2074542 0.6655767 1.502457 116 0.6738930
Apr 7 1.2097456 0.6144996 1.627340 148 0.6216863
May 5 1.0916578 0.5773407 1.732079 190 0.6782851
Jun 6 0.8187906 0.3782271 2.643914 190 0.4569757
Jul 5 1.2409112 0.6651524 1.503415 190 0.7710215
Aug 6 1.3315053 0.6883663 1.452715 155 0.7431273
Sep 6 1.4385527 0.7183743 1.392032 141 0.8028716
Oct 5 1.0119723 0.5603482 1.784604 133 0.6287737
Nov 6 1.1393088 0.5559154 1.798835 338 0.6358603

Diversity indices of Beeston Pond in 2007
Month richness shannon simpson invsimpson total evenness
Jan 2 0.0859155 0.0333238 30.008621 59 0.1239499
Feb 5 1.5175509 0.7609882 1.314081 118 0.9429074
Mar 5 1.2620186 0.6813440 1.467687 125 0.7841363
Apr 5 1.1180924 0.6249872 1.600033 198 0.6947099
May 6 1.2204911 0.6224036 1.606674 105 0.6811691
Jun 4 0.5150785 0.2388102 4.187425 205 0.3715506
Jul 4 0.9456251 0.5454277 1.833424 184 0.6821243
Aug 5 1.1136931 0.5734000 1.743983 100 0.6919765
Sep 5 0.8450589 0.5081921 1.967760 440 0.5250646
Oct 4 0.8707255 0.5401168 1.851452 191 0.6280957
Nov 5 1.0305089 0.5507771 1.815616 141 0.6402912
Dec 4 1.1588299 0.6478000 1.543686 100 0.8359191

Diversity indices of Beeston Pond in 2008
Month richness shannon simpson invsimpson total evenness
Jan 4 0.7905695 0.4256929 2.349112 127 0.5702753
Feb 2 0.1204560 0.0505988 19.763333 77 0.1737813
Mar 4 0.5327355 0.2591507 3.858758 137 0.3842874